<include file='Base:header' />
	<style type="text/css">
		.more_content{
			line-height: 24px;
			max-height: 48px;
			overflow : hidden;
			text-overflow: ellipsis;
			display: -webkit-box;
			-webkit-line-clamp: 2;
			-webkit-box-orient: vertical;
		}
		.more{
			margin-right: 12px;
			font-size: 17px;
			line-height: 24px;
			color: black;
			display: block;
			float: right;
		}
		.location{
			color: #656889;
			line-height: 16px;
			font-size: 12px;
			display: inline-block;
			background: url(__IMG__/location.png) no-repeat;
			text-indent:2em;
		}
	</style>
	
	

		<div class="approval">
			<h1 class="title">
				<a class="back" href="{$goback}">
					<img class="fl" src="__IMG__/back.png" style="margin-left: 5%;"/>
				</a>
				审批
				<a class="home" href="__APP__">
					<img class="fl" src="__IMG__/home_logo.png" style="margin-right: 5%;"/>
				</a>
			</h1>
			<include file='Base:_userinfo' />
				
 			<div class="weui-flex" style="margin-top: 20px;">
				<div class="weui-flex__item plain" style="text-align: center;">
					<a href="{:U('',['status'=>0])}"  class="weui-btn weui-btn_plain-primary weui-btn_mini" >待审批</a>
				</div>
				<div class="weui-flex__item plain" style="text-align: center;">
					<a href="{:U('',['status'=>1])}"  class="weui-btn weui-btn_plain-primary weui-btn_mini" >已通过</a>
				</div>
				<div class="weui-flex__item plain" style="text-align: center;">
					<a href="{:U('',['status'=>2])}"  class="weui-btn weui-btn_plain-primary weui-btn_mini" >已退回</a>
				</div>
			</div>
			<!--<eq name="_GET[status]" value='0'>
				 <div class="weui-flex" style="margin-top: 20px;">
	 				<div class="weui-flex__item" style="text-align: center;">
						<button href="" id='audit_all' class="weui-btn weui-btn_mini weui-btn_primary ajax-get" >全部通过</a>
					</div>
				 </div>
			</eq>-->
			 
			<!--<php>$type = C('APPLY_TYPE');$vacatype = C('VACATION_TYPE');</php>
			<notempty name='list'>
			
				<volist name='list' id='vo'>
				<php>$unaudit[] = $vo[id];</php>
					<div class="weui-cells">
						<div class="weui-media-box weui-media-box_text" status="{$vo.status}" style="padding-bottom: 5px;">
							<h4 class="weui-media-box__title" style="white-space: inherit;word-break: inherit;">
								<span>{$vo.name}</span>
							</h4>
							<p class="weui-media-box__desc" style="margin-bottom: 8px;overflow: inherit;display:block;height: auto;">
								<eq name='vo.type' value='4'>
									<span>时间:{$vo[start_time] ? $vo[start_time] : $vo[end_time]}</span>
									<else />
									<span>时间:{$vo[start_time]}至{$vo[end_time]}</span>
								</eq>
							</p>
						    <p class="weui-media-box__desc" style="margin-bottom: 8px;overflow: inherit;display:block;height: auto;">
						    	类型:{$vo[type] == 2 ? $vacatype[$vo[vacate_type]] :$type[$vo[type]]}
						    </p>
						    <p class="weui-media-box__desc" style="overflow: inherit;display:block;height: auto;margin-bottom: 8px">
						    	<notempty name='vo.content'>原因:{$vo.content}</notempty>
						    </p>
							<div class="weui-cell__ft">
								<php>$stuInfo = $status[$vo[status]];</php>
								<span>{$stuInfo[0]}</span><i class="weui-icon-{$stuInfo[1]} fr"></i>
						    </div>
						</div>
						<notempty name='vo.img_path'>
							<php>$imgBox = json_decode($vo[img_path],true);$domain = C('IMG_DOMAIN')</php>
							<div class="weui-flex approval_img" style="padding: 15px;">
								<ul class="weui-media-box_text" id="uploaderFilesBox">
									<volist name='imgBox' id='voimg'>
										<li class='weui-uploader__file'>
											<img  src="{$domain}/{$voimg}" alt="" style="width: 100%;height: 100%;" /> 
										</li>
									</volist>							
								</ul>
							</div>
						</notempty>
						<div class="weui-flex" style="margin-top: 5px;margin-bottom: 5px;">
							<div class="weui-flex__item"></div>	
							<div class="weui-flex__item"></div>	
							<switch name='vo.status'>
							<case value='0'>
								<div class="weui-flex__item" style="text-align: center;">
									<a href="{:U('auditPass',['id'=>$vo[id]])}" class="weui-btn weui-btn_mini weui-btn_primary ajax-get">通过</a>
								</div>					
								<div class="weui-flex__item" style="text-align: center;">
									<a href="{:U('auditReject',['id'=>$vo[id]])}" class="weui-btn weui-btn_mini weui-btn_warn return" id='{$vo.id}'>退回</a>
								</div>
							</case>
							<case value='1'>
								<div class="fr">
									<span style="color:green">已通过</span>
									<i class="weui-icon-success" style="margin-top: -5px;"></i>
								</div>
							</case>
							<case value='2'>
								<div class="fr">
									<span style="color:red">已拒绝</span>
									<i class="weui-icon-warn" style="margin-top: -5px;"></i>
								</div>
							</case>
							</switch>
						</div>
					</div>
				    <p class="weui-media-box__desc" style="overflow: inherit;display:block;height: auto;padding: 5px 15px;">
				    	<notempty name='vo.map'>
				    		<span class="location">
				    			{$vo.map}
				    		</span>
				   		</notempty>
				    </p>
				</volist>
				<else />
				<p class='nodata'>暂无数据</p>
			</notempty>-->
	 		<div class="weui-loadmore" id='loading' style="display:none">
			  <i class="weui-loading"></i>
			  <span class="weui-loadmore__tips">正在加载</span>
			</div> 
		</div>
		
		
		<include file='Base:footer' />
		<script src="https://res.wx.qq.com/open/js/jweixin-1.0.0.js" type="text/javascript" charset="utf-8"></script>
		<script src="http://wechat.idea.3xy.me/Wechat/Api/wxjsConfig/accode/78d53979062e584600b7e0e1ab4ae638/debug/false"></script>
		<script type="text/javascript">
			var _type = "{$_GET[status]}";
			var nextpage = 1;     
			var loading = false;  //状态标记
			var page = 1;
			var ids = "";
			function show_alist(_page,_type){
				$.ajax({
					type:"post",
					url:"index.php?g=&m=Approval&a=approverList",
					data:{'status': _type,'page':page,'limit':3},
					beforeSend:function(){
						loading = true;
						$('#loading').css("display","block");
							  
					},
					success:function(ret){
						if(ret.ids){
							ids += ","+ret.ids;
						}
						if(ids.substr(0,1)==","){
							ids = ids.substr(1);
						}
						if(ret.list.length>0){
							for(var i in ret.list){
								var status = ret.list[i].app_status;
									var audit = statusTemplate(ret.list[i].audit);//获取审核相关人员
									var html = "";
									var type_num = ret.list[i].type-1;
									var type_text = ["外出","假期","加班","补打卡","加班[系统提交]"];
									var type = ret.list[i].vacate_type_name;
									if(type_num == "1"){
									//	var leave_num = ret.list[i].vacate_type_name;
									//	leave_num = leave_num.substring(2,3);
									//	var leave_text = ["病假（半日薪）","调休","事假","年假","病假（最低薪）","婚假","产假","陪产假","其他","病假（全日薪）"];
										//type = leave_text[leave_num];
									}
									
									var img = "";
									var img_html = "";
									if(ret.list[i].img_path != '' && ret.list[i].img_path != null){
										var str = JSON.parse(ret.list[i].img_path);
										for(var j in str){
											img += "<li class='weui-uploader__file'>"+	
														"<img src='http://web.idea.3xy.me/insight20170117_attendance/"+str[j]+"' style='width: 100%;height: 100%;'>"+	
													"</li>";
											img_html = "<div class='weui-flex approval_img' style='padding:15px'>"+
															"<ul class='weui-media-box_text' id='uploaderFilesBox'>"+
																""+img+""+
															"</ul>"	+
														"</div>";
										}
									}
									
									if(ret.list[i].content == null){
										ret.list[i].content = "无";
									}
									var status_html = "";
									switch (status){
										case "0":
											status_html = "<div class='weui-flex__item' style='text-align:center;'>"+
																"<a href='index.php?g=&m=Approval&a=auditPass&id="+ret.list[i].id+"' class='weui-btn weui-btn_mini weui-btn_primary pass'>通过</a>"+
															"</div>"+	
															"<div class='weui-flex__item' style='text-align:center;'>"+
																"<a href='index.php?g=&m=Approval&a=auditReject&id="+ret.list[i].id+"' class='weui-btn weui-btn_mini weui-btn_warn return'>退回</a>"+
															"</div>";	
											break;
										case "1":
											status_html = "<div class='fr'><span style='color:green'>已通过</span><i class='weui-icon-success' style='margin-top:-5px;'></i></div>";
											break;
										case "2":
											status_html = "<div class='fr'><span style='color:red'>已拒绝</span><i class='weui-icon-warn' style='margin-top:-5px;'></i></div>";
											break;
									}
									var map_html = "";
									if(ret.list[i]._map){
										
										map_html = 	"<p	class='weui-media-box__desc' style='overflow: inherit;display:block;height: auto;padding: 5px 15px;'>"+
														"<span class='location'>"+ret.list[i]._map+"</span>"+
													"</p>"	;
									}
									var time_html = "";
									if(ret.list[i].start_time && ret.list[i].end_time){
										time_html = "<p class='weui-media-box__desc' style='margin-bottom:8px;overflow;inherit;display:block;height: auto;'>"+
													"<span>时间："+ret.list[i].start_time+" 至 "+ret.list[i].end_time+"</span>"+
													"</p>";
									}else if(ret.list[i].start_time){
										time_html = "<p class='weui-media-box__desc' style='margin-bottom:8px;overflow;inherit;display:block;height: auto;'>"+
													"<span>时间："+ret.list[i].start_time+"</span>"+
													"</p>";
									}else if(ret.list[i].end_time){
										time_html = "<p class='weui-media-box__desc' style='margin-bottom:8px;overflow;inherit;display:block;height: auto;'>"+
													"<span>时间："+ret.list[i].end_time+"</span>"+
													"</p>";
									}
									html += "<div class='weui-cells list_item' itemid='"+ret.list[i].id+"'>"+
												"<div class = 'weui-media-box weui-media-box_text' style='padding-bottom: 5px;'>"+
													"<h4 class = 'weui-media-box__title' style='white-space: inherit;word-break: inherit;'>"+
													"<span>"+ret.list[i].name+"</span>"+
													"</h4>"+
													""+time_html+""+
													"<p class='weui-media-box__desc' style='margin-bottom: 8px;overflow: inherit;display:block;height: auto;'>"+
													"类型："+type+""+
													"</p>"+
													"<p class='weui-media-box__desc' style='overflow: inherit;display:block;height: auto;margin-bottom: 8px'>"+
													"原因："+ret.list[i].content+""+
													"</p>"+
												"</div>"+
												""+img_html+""+
												"<div class = 'weui-media-box weui-media-box_text' style='padding-bottom: 5px;'>"+audit+
												"</div>"+
												"<div class='weui-flex' style='margin-top: 5px;margin-bottom: 5px;'>"+
													"<div class='weui-flex__item'></div>"+
													"<div class='weui-flex__item'></div>"+
													""+status_html+""+
												"</div>"+
											"</div>"+
											""+map_html+"";
									$("#loading").before(html);
							}
							nextpage ++; 
							page++;
						}else{
							var null_html = "<p class='nodata'>暂无更多数据</p>";
							$("#loading").before(null_html);
							$(document.body).destroyInfinite();//销毁滚动加载
						}
						
						$('#loading').css('display','none');
						loading = false;
						$("#audit_all").attr("href","index.php?g=&m=Approval&a=auditAll&ids="+ids+"")
					}
				});
			}
			//发送请求
			function ajaxGet(_url, _data, _target) {
				$.ajax({
					type: 'get',
					url: _url,
					data: _data,
					success: function(ret) {
						if(ret.status) {
							_target.remove()
							$.toast(ret.info);
						} else {
							$.alert(ret.info);
						}
					}

				});
			}			
			
			show_alist(1,_type);//初始化出数据
			/*下拉加载*/
			$(document.body).infinite(10).on("infinite", function() {
			  if(loading) return;
		      show_alist(nextpage,_type);//执行数据加载

			});
			
			
			$("body").on("click",".return",function(event){
				event.preventDefault();
				var _this = $(this)
				var rejectUrl = _this.attr('href');
				var _target = _this.parents('.list_item')
				$.prompt({
				  title: '理由',
//				  text: '内容文案',
				  empty: true, // 是否允许为空
				  onOK: function (input) {
				    //点击确认,执行ajax发送函数
					ajaxGet(rejectUrl,{reject_reason:input},_target);
				    return false;
				  },
				  onCancel: function () {
				    //点击取消
				  }
				});
			})
			
			
			$("body").on("click",".pass",function(event){
				event.preventDefault();
				var _this = $(this)
				console.log(_this)
				var rejectUrl = _this.attr('href');
				var _target = _this.parents('.list_item')
				ajaxGet(rejectUrl,{},_target);
			})
			
			var falg = false;
			$("body").on("touchstart touchmove touchend",".approval_img img",function(){
				switch(event.type) {
			        case 'touchstart':
			            falg = false;
			            break;
			        case 'touchmove':
			            falg = true;
			             break;
			        case 'touchend':
			            if( !falg ) {
			            	var arr = [];
							$('.approval_img img').each(function(){
						   		arr.push($(this).attr('src'));
							})
							var src = $(this).attr("src");
							wx.previewImage({
						      	current: src,
						      	urls: arr
						   });
			            }
			        break;
			    }
			})
			
			function GetArgsFromHref(sHref, sArgName){
			      var args    = sHref.split("?");
			      var retval = "";
			    
			      if(args[0] == sHref) /*参数为空*/
			      {
			           return retval; /*无需做任何处理*/
			      }  
			      var str = args[1];
			      args = str.split("&");
			      for(var i = 0; i < args.length; i ++)
			      {
			          str = args[i];
			          var arg = str.split("=");
			          if(arg.length <= 1) continue;
			          if(arg[0] == sArgName) retval = arg[1]; 
			      }
			      return retval;
			}
			
			var href_status = GetArgsFromHref(window.location.href,'status');
			$(".weui-flex .plain:eq("+href_status+") a").addClass("weui-btn_primary");
			$(".weui-flex .plain:eq("+href_status+") a").removeClass("weui-btn_plain-primary");
		</script>